<?php
/**
 * Description
 * 
 * PHP version 7
 * 
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-25 10:24:35
 * @lastTime 2020-05-02 00:32:32
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */

namespace Test\Unit;

use Design\Structural\DataMapper\User;
use Design\Structural\DataMapper\UserMapper;
use Design\Structural\DataMapper\StorageAdapter;

class DataMapperTest extends \Test\BaseTest
{


    public function testCanFindUserFromStorage()
    {
        $storage    = new StorageAdapter([1 => ['username' => 'ryu', 'email' => 'mo5467@126.com']]);
        $userMapper = new UserMapper($storage);
        $user = $userMapper->findById(1);
        $this->assertInstanceOf(User::class, $user);
        $this->assertSame('ryu', $user->getUsername());
        $this->assertSame('mo5467@126.com', $user->getEmail());


    }//end testCanFindUserFromStorage()


    public function testWillThrowException()
    {
        $this->expectException(\InvalidArgumentException::class);

        $storage    = new StorageAdapter([]);
        $userMapper = new UserMapper($storage);
        $user       = $userMapper->findById(1);

    }//end testWillThrowException()


}//end class
